package com.whmskj.xjlhbc.mobile.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.whmskj.xjlhbc.core.AjaxResult;
import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhbc.domain.Bczl01Subczjlb;
import com.whmskj.xjlhbc.domain.Bczl01czcyjlb;
import com.whmskj.xjlhbc.domain.Bczl02jdjlb;
import com.whmskj.xjlhbc.domain.Bczl03jdzjlb;
import com.whmskj.xjlhbc.domain.Bczl03jdcyjlb;
import com.whmskj.xjlhbc.domain.PersonnelManagementDataSheets;
import com.whmskj.xjlhbc.mapper.Bczl01SubczjlbMapper;
import com.whmskj.xjlhbc.mapper.Bczl01czcyjlbMapper;
import com.whmskj.xjlhbc.mapper.Bczl02jdjlbMapper;
import com.whmskj.xjlhbc.mapper.Bczl03jdzjlbMapper;
import com.whmskj.xjlhbc.mapper.Bczl03jdcyjlbMapper;
import com.whmskj.xjlhbc.service.IBczl01SubczjlbService;
import com.whmskj.xjlhbc.service.IBczl01czcyjlbService;
import com.whmskj.xjlhbc.service.IBczl02jdjlbService;
import com.whmskj.xjlhbc.service.IBczl03jdzjlbService;
import com.whmskj.xjlhbc.service.IBczl03jdcyjlbService;
import com.whmskj.xjlhbc.service.IPersonnelManagementDataSheetsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
import java.math.BigDecimal;

/**
 * 质量日报Controller
 */
@RestController
@Tag(name = "质量日报", description = "质量日报管理（次轴和降等）")
@RequestMapping("/quality")
public class QualityReportController {

    @Autowired
    private IBczl01SubczjlbService subczService;
    
    @Autowired
    private IBczl03jdzjlbService degradationService;
    
    @Autowired
    private IBczl01czcyjlbService subczReviewService;
    
    @Autowired
    private IBczl03jdcyjlbService degradationReviewService;
    
    @Autowired
    private Bczl01SubczjlbMapper subczMapper;
    
    @Autowired
    private Bczl03jdzjlbMapper degradationMapper;
    
    @Autowired
    private Bczl01czcyjlbMapper subczReviewMapper;
    
    @Autowired
    private Bczl03jdcyjlbMapper degradationReviewMapper;
    
    @Autowired
    private Bczl02jdjlbMapper degradationDetailMapper;
    
    
    @Autowired
    private IBczl02jdjlbService degradationDetailService;

    /**
     * 获取质量日报列表（次轴和降等）
     */
    @GetMapping("/list")
    @Operation(description = "质量日报列表")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult list(@RequestParam(required = false) String type,
                          @RequestParam(required = false) String weaverNumber,
                          @RequestParam(required = false) String problem,
                          @RequestParam(required = false) String benb,
                          @RequestParam(required = false) String jsdcg,
                          @RequestParam(required = false) String reporter,
                          @RequestParam(required = false) String startDate,
                          @RequestParam(required = false) String endDate) {
        try {
            Page.startPage();
            
            if ("jd".equals(type)) {
                return getDegradationList(reporter, startDate, endDate);
            } else {
                return getSubczList(weaverNumber, problem, benb, jsdcg, reporter, startDate, endDate);
            }
        } catch (Exception e) {
            return AjaxResult.error("查询失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取次轴记录列表
     */
    private AjaxResult getSubczList(String weaverNumber, String problem, String benb, 
                                   String jsdcg, String reporter, String startDate, String endDate) {
        LambdaQueryWrapper<Bczl01Subczjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.hasText(weaverNumber), Bczl01Subczjlb::getWeaverNumber, weaverNumber);
        wrapper.like(StringUtils.hasText(problem), Bczl01Subczjlb::getProblem, problem);
        wrapper.eq(StringUtils.hasText(benb), Bczl01Subczjlb::getBenb, benb);
        wrapper.eq(StringUtils.hasText(jsdcg), Bczl01Subczjlb::getJsdcg, jsdcg);
        wrapper.eq(StringUtils.hasText(reporter), Bczl01Subczjlb::getReporter, reporter);
        wrapper.ge(StringUtils.hasText(startDate), Bczl01Subczjlb::getDateReported, startDate);
        wrapper.le(StringUtils.hasText(endDate), Bczl01Subczjlb::getDateReported, endDate);
        wrapper.orderByDesc(Bczl01Subczjlb::getReportingTime);
        
        List<Bczl01Subczjlb> list = subczMapper.selectList(wrapper);
        return Page.getDataTable(list);
    }
    
    /**
     * 获取降等记录列表
     */
    private AjaxResult getDegradationList(String reporter, String startDate, String endDate) {
        LambdaQueryWrapper<Bczl03jdzjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasText(reporter), Bczl03jdzjlb::getReporter, reporter);
        wrapper.ge(StringUtils.hasText(startDate), Bczl03jdzjlb::getDateReported, startDate);
        wrapper.le(StringUtils.hasText(endDate), Bczl03jdzjlb::getDateReported, endDate);
        wrapper.orderByDesc(Bczl03jdzjlb::getReportingTime);
        
        List<Bczl03jdzjlb> list = degradationMapper.selectList(wrapper);
        return Page.getDataTable(list);
    }

    /**
     * 获取次轴记录详情
     */
    @GetMapping("/subcz/detail/{id}")
    @Operation(description = "次轴记录详情")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult subczDetail(@PathVariable Long id) {
        try {
            Bczl01Subczjlb subcz = subczMapper.selectById(id);
            if (subcz == null) {
                return AjaxResult.error("记录不存在");
            }
            
            // 记录查阅信息
            recordSubczReview(id);
            
            // 获取查阅记录
            List<Bczl01czcyjlb> reviewRecords = getSubczReviewRecordsInternal(id);
            
            // 构建返回数据
            Map<String, Object> result = new HashMap<>();
            result.put("detail", subcz);
            result.put("reviewRecords", reviewRecords);
            
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("获取详情失败：" + e.getMessage());
        }
    }

    /**
     * 提交/编辑次轴记录
     */
    @PostMapping("/subcz/save")
    @Operation(description = "次轴记录提交")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    @Transactional
    public AjaxResult subczSave(@RequestBody Bczl01Subczjlb body) {
        try {
            Long id = body.getId();
            
            // 设置默认值
            if (body.getReportingTime() == null) {
                body.setReportingTime(new Date());
            }
            if (body.getReporter() == null || body.getReporter().isEmpty()) {
                body.setReporter(getCurrentUserName());
            }
            if (body.getQrrzt() == null || body.getQrrzt().isEmpty()) {
                body.setQrrzt("待确认");
            }
            if (body.getListStatus() == null || body.getListStatus().isEmpty()) {
                body.setListStatus("待确认");
            }
            
            int result;
            if (id != null) {
                // 更新
                result = subczMapper.updateById(body);
            } else {
                // 新增
                result = subczMapper.insert(body);
            }
            
            return AjaxResult.success(result > 0);
        } catch (Exception e) {
            return AjaxResult.error("保存失败：" + e.getMessage());
        }
    }

    /**
     * 删除次轴记录
     */
    @PostMapping("/subcz/delete/{id}")
    @Operation(description = "次轴记录删除")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    @Transactional
    public AjaxResult subczDelete(@PathVariable Long id) {
        try {
            // 检查是否为当天提交的数据
            Bczl01Subczjlb subcz = subczMapper.selectById(id);
            if (subcz == null) {
                return AjaxResult.error("记录不存在");
            }
            
            String today = DateUtil.today();
            if (!today.equals(subcz.getDateReported())) {
                return AjaxResult.error("只能删除当天提交的数据");
            }
            
            int result = subczMapper.deleteById(id);
            return AjaxResult.success(result > 0);
        } catch (Exception e) {
            return AjaxResult.error("删除失败：" + e.getMessage());
        }
    }

    /**
     * 确认次轴记录
     */
    @PostMapping("/subcz/confirm/{id}")
    @Operation(description = "确认次轴记录")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult subczConfirm(@PathVariable Long id, @RequestParam String confirmer) {
        try {
            Bczl01Subczjlb subcz = subczMapper.selectById(id);
            if (subcz == null) {
                return AjaxResult.error("记录不存在");
            }
            
            subcz.setConfirmed(confirmer);
            subcz.setQrrzt("已确认");
            subcz.setQrTime(new Date());
            subcz.setListStatus("已确认");
            
            int result = subczMapper.updateById(subcz);
            return AjaxResult.success(result > 0);
        } catch (Exception e) {
            return AjaxResult.error("确认失败：" + e.getMessage());
        }
    }

    /**
     * 获取浆纱工人员列表
     */
    @GetMapping("/jiangshaWorkers")
    @Operation(description = "获取浆纱工人员列表（模糊匹配包含'浆纱'的岗位）")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getJiangShaWorkers() {
        try {
            List<String> workers = subczService.getJiangShaWorkersByPosition("浆纱");
            return AjaxResult.success(workers);
        } catch (Exception e) {
            return AjaxResult.error("获取浆纱工列表失败：" + e.getMessage());
        }
    }

    /**
     * 获取织机号列表
     */
    @GetMapping("/weaverNumbers")
    @Operation(description = "获取织机号列表（仅查询设备名称为'织布机'的机台）")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getWeaverNumbers() {
        try {
            List<String> numbers = subczService.getWeaverNumbers();
            return AjaxResult.success(numbers);
        } catch (Exception e) {
            return AjaxResult.error("获取织机号列表失败：" + e.getMessage());
        }
    }

    /**
     * 根据织机号获取设备信息
     */
    @GetMapping("/equipment/{weaverNumber}")
    @Operation(description = "根据织机号获取设备信息")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getEquipmentByWeaverNumber(@PathVariable String weaverNumber) {
        try {
            Object equipment = subczService.getEquipmentByWeaverNumber(weaverNumber);
            return AjaxResult.success(equipment);
        } catch (Exception e) {
            return AjaxResult.error("获取设备信息失败：" + e.getMessage());
        }
    }

    /**
     * 获取班别选项
     */
    @GetMapping("/shiftOptions")
    @Operation(description = "获取班别选项")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getShiftOptions() {
        try {
            Map<String, String> options = new HashMap<>();
            options.put("甲", "甲班");
            options.put("乙", "乙班");
            return AjaxResult.success(options);
        } catch (Exception e) {
            return AjaxResult.error("获取班别选项失败：" + e.getMessage());
        }
    }

    /**
     * 获取降等记录详情
     */
    @GetMapping("/jd/detail/{id}")
    @Operation(description = "降等记录详情")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult jdDetail(@PathVariable Long id) {
        try {
            Bczl03jdzjlb degradation = degradationMapper.selectById(id);
            if (degradation == null) {
                return AjaxResult.error("记录不存在");
            }
            
            // 记录查阅信息
            recordDegradationReview(id);
            
            // 获取查阅记录
            List<Bczl03jdcyjlb> reviewRecords = getDegradationReviewRecordsInternal(id);
            
            // 按照页面格式返回数据
            Map<String, Object> result = new HashMap<>();
            result.put("date", degradation.getDateReported());
            result.put("bujijiang", degradation.getBjj() != null ? degradation.getBjj() + "米" : "0米");
            result.put("bujishijiang", degradation.getBjSj() != null ? degradation.getBjSj() + "米" : "0米");
            result.put("zhunzhengjiang", degradation.getZzj() != null ? degradation.getZzj() + "米" : "0米");
            result.put("zhunzhengshijiang", degradation.getZzSj() != null ? degradation.getZzSj() + "米" : "0米");
            result.put("fangbujiang", degradation.getFbj() != null ? degradation.getFbj() + "米" : "0米");
            result.put("fangbushijiang", degradation.getFbSj() != null ? degradation.getFbSj() + "米" : "0米");
            result.put("reviewRecords", reviewRecords);
            
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("获取详情失败：" + e.getMessage());
        }
    }

    /**
     * 获取布机降等详情
     */
    @GetMapping("/jd/bujijiang/detail/{id}")
    @Operation(description = "布机降等详情")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult bujijiangDetail(@PathVariable Long id) {
        return getDegradationDetail(id, "布机", "布机降等详情");
    }

    /**
     * 获取浆纱降等详情
     */
    @GetMapping("/jd/jiangshajiang/detail/{id}")
    @Operation(description = "浆纱降等详情")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult zhunzhengjiangDetail(@PathVariable Long id) {
        return getDegradationDetail(id, "浆纱", "浆纱降等详情");
    }

    /**
     * 获取纺部降等详情
     */
    @GetMapping("/jd/fangbujiang/detail/{id}")
    @Operation(description = "纺部降等详情")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult fangbujiangDetail(@PathVariable Long id) {
        return getDegradationDetail(id, "纺部", "纺部降等详情");
    }


    /**
     * 获取降等详情的公共方法
     */
    private AjaxResult getDegradationDetail(Long id, String category, String errorMessage) {
        try {
            // 先查询降等主记录
            Bczl03jdzjlb degradation = degradationMapper.selectById(id);
            if (degradation == null) {
                return AjaxResult.error("降等记录不存在");
            }
            
            // 根据降等记录ID查询详细数据
            List<Bczl02jdjlb> detailList = degradationDetailService.getByMainIdAndType(id, category);
            
            // 转换为前端需要的格式
            List<Map<String, Object>> details = convertDegradationDetails(detailList);
            
            return AjaxResult.success(details);
        } catch (Exception e) {
            return AjaxResult.error("获取" + errorMessage + "失败：" + e.getMessage());
        }
    }
    
    /**
     * 转换降等详情数据格式
     */
    private List<Map<String, Object>> convertDegradationDetails(List<Bczl02jdjlb> detailList) {
        List<Map<String, Object>> details = new ArrayList<>();
        for (Bczl02jdjlb detail : detailList) {
            Map<String, Object> detailMap = new HashMap<>();
            
            // 基本信息
            detailMap.put("id", detail.getId());
            detailMap.put("category", detail.getCategory());
            detailMap.put("dateReported", detail.getDateReported());
            detailMap.put("variety", detail.getVarieties());
            detailMap.put("machineNumber", detail.getCnumber());
            detailMap.put("meters", detail.getMillimeters());
            detailMap.put("actualDrop", detail.getMsjms());
            detailMap.put("defectName", detail.getBugName());
            
            // 甲班信息
            detailMap.put("classAWorkNumber", detail.getJbgh());
            detailMap.put("classAEmployee", detail.getJbyg());
            detailMap.put("classAMeters", detail.getJbms());
            
            // 乙班信息
            detailMap.put("classBWorkNumber", detail.getYbgh());
            detailMap.put("classBEmployee", detail.getYbyg());
            detailMap.put("classBMeters", detail.getYbms());
            
            // 备注和关联信息
            detailMap.put("remarks", detail.getRemarks());
            detailMap.put("mainTableId", detail.getGltjzb());
            
            // 组合字段（保持兼容性）
            detailMap.put("classAWorkNumberMeters", formatWorkNumberMeters(detail.getJbgh(), detail.getJbms()));
            detailMap.put("classBWorkNumberMeters", formatWorkNumberMeters(detail.getYbgh(), detail.getYbms()));
            
            details.add(detailMap);
        }
        return details;
    }
    
    /**
     * 格式化工号/米数组合
     */
    private String formatWorkNumberMeters(String workNumber, BigDecimal meters) {
        if (workNumber != null && meters != null) {
            return workNumber + "/" + meters;
        }
        return "";
    }

    /**
     * 获取次轴查阅记录
     */
    @GetMapping("/subcz/review/{id}")
    @Operation(description = "获取次轴查阅记录")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getSubczReviewRecords(@PathVariable Long id) {
        try {
            List<Bczl01czcyjlb> reviewRecords = getSubczReviewRecordsInternal(id);
            return AjaxResult.success(reviewRecords);
        } catch (Exception e) {
            return AjaxResult.error("获取查阅记录失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取次轴查阅记录（内部方法）
     */
    private List<Bczl01czcyjlb> getSubczReviewRecordsInternal(Long id) {
        LambdaQueryWrapper<Bczl01czcyjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Bczl01czcyjlb::getLinkSubaxisRecords, id)
               .orderByDesc(Bczl01czcyjlb::getAccessTime);
        
        return subczReviewMapper.selectList(wrapper);
    }
    
    /**
     * 获取降等查阅记录
     */
    @GetMapping("/jd/review/{id}")
    @Operation(description = "获取降等查阅记录")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getDegradationReviewRecords(@PathVariable Long id) {
        try {
            List<Bczl03jdcyjlb> reviewRecords = getDegradationReviewRecordsInternal(id);
            return AjaxResult.success(reviewRecords);
        } catch (Exception e) {
            return AjaxResult.error("获取查阅记录失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取降等查阅记录（内部方法）
     */
    private List<Bczl03jdcyjlb> getDegradationReviewRecordsInternal(Long id) {
        LambdaQueryWrapper<Bczl03jdcyjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Bczl03jdcyjlb::getCygljdjlzb, id)
               .orderByDesc(Bczl03jdcyjlb::getAccessTime);
        
        return degradationReviewMapper.selectList(wrapper);
    }

    /**
     * 获取质量日报统计信息
     */
    @GetMapping("/statistics")
    @Operation(description = "获取质量日报统计信息")
    @ApiResponse(content = @Content(schema = @Schema(anyOf = {AjaxResult.class})))
    public AjaxResult getStatistics(@RequestParam String date, @RequestParam(required = false) String type) {
        try {
            if ("jd".equals(type)) {
                return getDegradationStatistics(date);
            } else {
                return getSubczStatistics(date);
            }
        } catch (Exception e) {
            return AjaxResult.error("获取统计信息失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取次轴统计信息
     */
    private AjaxResult getSubczStatistics(String date) {
        LambdaQueryWrapper<Bczl01Subczjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Bczl01Subczjlb::getDateReported, date);
        
        List<Bczl01Subczjlb> records = subczMapper.selectList(wrapper);
        
        Map<String, Object> statistics = new HashMap<>();
        statistics.put("totalCount", records.size());
        statistics.put("confirmedCount", records.stream().filter(r -> "已确认".equals(r.getQrrzt())).count());
        statistics.put("pendingCount", records.stream().filter(r -> "待确认".equals(r.getQrrzt())).count());
        statistics.put("records", records);
        
        return AjaxResult.success(statistics);
    }
    
    /**
     * 获取降等统计信息
     */
    private AjaxResult getDegradationStatistics(String date) {
        LambdaQueryWrapper<Bczl03jdzjlb> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Bczl03jdzjlb::getDateReported, date);
        
        List<Bczl03jdzjlb> records = degradationMapper.selectList(wrapper);
        
        Map<String, Object> statistics = new HashMap<>();
        statistics.put("totalCount", records.size());
        // 降等记录暂时不统计确认状态
        statistics.put("confirmedCount", 0);
        statistics.put("pendingCount", records.size());
        statistics.put("records", records);
        
        return AjaxResult.success(statistics);
    }

    /**
     * 记录次轴查阅信息
     */
    private void recordSubczReview(Long recordId) {
        try {
            String currentUser = getCurrentUserName();
            String currentPosition = getCurrentUserPosition();
            
            // 检查是否已经查阅过
            LambdaQueryWrapper<Bczl01czcyjlb> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Bczl01czcyjlb::getLinkSubaxisRecords, recordId)
                   .eq(Bczl01czcyjlb::getOtherOrganiser, currentUser);
            
            Bczl01czcyjlb existingReview = subczReviewMapper.selectOne(wrapper);
            if (existingReview != null) {
                // 已经查阅过，不重复记录
                return;
            }
            
            // 创建新的查阅记录
            Bczl01czcyjlb reviewRecord = new Bczl01czcyjlb();
            reviewRecord.setLinkSubaxisRecords(recordId);
            reviewRecord.setOtherOrganiser(currentUser);
            reviewRecord.setPositions(currentPosition);
            reviewRecord.setAccessTime(new Date());
            
            subczReviewMapper.insert(reviewRecord);
        } catch (Exception e) {
            // 查阅记录失败不影响主流程，只记录日志
            System.err.println("记录次轴查阅信息失败：" + e.getMessage());
        }
    }
    
    /**
     * 记录降等查阅信息
     */
    private void recordDegradationReview(Long recordId) {
        try {
            String currentUser = getCurrentUserName();
            String currentPosition = getCurrentUserPosition();
            
            // 检查是否已经查阅过
            LambdaQueryWrapper<Bczl03jdcyjlb> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Bczl03jdcyjlb::getCygljdjlzb, recordId)
                   .eq(Bczl03jdcyjlb::getOtherOrganiser, currentUser);
            
            Bczl03jdcyjlb existingReview = degradationReviewMapper.selectOne(wrapper);
            if (existingReview != null) {
                // 已经查阅过，不重复记录
                return;
            }
            
            // 创建新的查阅记录
            Bczl03jdcyjlb reviewRecord = new Bczl03jdcyjlb();
            reviewRecord.setCygljdjlzb(recordId);
            reviewRecord.setOtherOrganiser(currentUser);
            reviewRecord.setPositions(currentPosition);
            reviewRecord.setAccessTime(new Date());
            
            degradationReviewMapper.insert(reviewRecord);
        } catch (Exception e) {
            // 查阅记录失败不影响主流程，只记录日志
            System.err.println("记录降等查阅信息失败：" + e.getMessage());
        }
    }
    
    /**
     * 获取当前用户名称
     */
    private String getCurrentUserName() {
        try {
            IPersonnelManagementDataSheetsService personnel = SpringUtil.getBean(IPersonnelManagementDataSheetsService.class);
            return personnel.getCorpMemberByLogin().getNick();
        } catch (Exception e) {
            return "系统用户";
        }
    }
    
    /**
     * 获取当前用户岗位
     */
    private String getCurrentUserPosition() {
        try {
            IPersonnelManagementDataSheetsService personnel = SpringUtil.getBean(IPersonnelManagementDataSheetsService.class);
            PersonnelManagementDataSheets personnelInfo = personnel.getByLoginUserId();
            if (personnelInfo != null) {
                return personnelInfo.getPositions1();
            }
            return "未知岗位";
        } catch (Exception e) {
            return "未知岗位";
        }
    }
}
